package cn.pxy.ysframework.web.Service.Impl;

import cn.pxy.ysframework.web.Entity.Category;
import cn.pxy.ysframework.web.Repository.ICategoryDao;
import cn.pxy.ysframework.web.Service.ICategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CategoryService implements ICategoryService {
    @Autowired
    private ICategoryDao categoryDao;
    @Override
    public List<Category> findAllCategory() {
        return categoryDao.findAll();
    }

    @Override
    public Page<Category> findAllCategoryWithPager(int page,int num) {
        Pageable pageable = PageRequest.of(page,num, Sort.Direction.DESC,"sort");
        return categoryDao.findAll(pageable);
    }

    @Override
    public Category findById(String id) {
        return categoryDao.findById(id).get();
    }
}
